/*
 * @Author: 贺楠 1071780426@qq.com
 * @Date: 2024-04-03 11:09:59
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-10-14 16:55:11
 * @FilePath: \newMould_BHZ\src\components\environmentalMonitorManage\testingRecord\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */



import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import CustomDialog from "@/components/environmentalMonitorManage/testingRecord/location/index.vue";

import {

    getEnvMonitorByFid, //监测记录
    getGantryCraneDetailsDataById, //龙门吊
    getBridgemachineByFid, //架桥机
    getCradledataByFid, //挂篮
    getTowercraneByFid, //塔吊
    getsmartElectricityDetailsDataById, //智慧用电

} from "@/api/request.js";
export default {
    props: [
        "dialogVisible",
        "dialogTitle",
        "statusNum",
        "currentRow",
        "fCompanyid",
        "showName",
        "status"
    ],
    data() {
        return {
            visible: "",
            loading: false,
            title: null,
            isLock: false,
            fCompanyids: null,
            fCompanynames: null,
            dialogHeight: null,
            formObj: [],
            locationShow: false, // WBS
            formData: {},
            btnShow: true,
            currentDetail: null,
        };
    },
    components: {
        publicForm,
        CustomDialog
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        statusNum: {
            handler(newVal) {
                if (newVal) {
                    this.edit(newVal);
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    // if (this.statusNum != 1) {
                    //     this.getDetail({
                    //         fId: this.currentDetail.fId
                    //     })
                    // }
                }
            },
            immediate: true,
        },
        fCompanyid: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanyids = newVal

                }
            },
            immediate: true,
        },
        showName: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal
                }
            },
            immediate: true,
        },
        status: {
            handler(newVal) {
                if (newVal) {
                    if (newVal == 0) { //环境检测记录
                        this.formObj = formJs.formObj1
                    } else if (newVal == 1) { //安全龙门吊
                        this.formObj = formJs.formObj2
                    } else if (newVal == 2) { //安全架桥机
                        this.formObj = formJs.formObj3
                    } else if (newVal == 3) { //安全塔吊
                        this.formObj = formJs.formObj4
                    } else if (newVal == 4) { //安全挂篮
                        this.formObj = formJs.formObj5
                    } else if (newVal == 5) { //安全挂篮
                        this.formObj = formJs.formObj6
                    }
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {

        this.btnShow = false;

        if (this.status == 0) { //环境检测记录
            this.getDetail({
                fId: this.currentDetail.emId
            })
        } else if (this.status == 1) { //安全龙门吊
            // this.formObj = formJs.formObj2
            this.getDetail({
                fId: this.currentRow.gcddId
            })
        } else if (this.status == 2) { //安全架桥机
            this.formObj = formJs.formObj3;
            this.getDetail({
                fId: this.currentRow.jqjRecordId
            })
        } else if (this.status == 3) { //安全塔吊
            this.formObj = formJs.formObj4;
            this.getDetail({
                fId: this.currentRow.tdRecordId
            })
        } else if (this.status == 4) { //安全挂篮
            this.formObj = formJs.formObj5;
            this.getDetail({
                fId: this.currentRow.cradledataId
            })
        } else if (this.status == 5) { //安全挂篮
            this.formObj = formJs.formObj6;
            this.getDetail({
                fId: this.currentRow.gcddId
            })
        }

        this.getHeight();
    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },
        closeDialog() {

            this.$emit("close");
        },
        selectChange(data, a, b) {
            console.log(data, a, b);
            if (b == "fCheckcompany") { //生产厂家
                this.formData.fCheckcompany = data.label; //检测单位
                this.formData.fEquipname = data.value //设备名称
            }
        },
        edit() {
            this.formData = this.$options.data.call(this).formData;
        },
        // 地图
        clickDialog(index, prop) {
            if (prop == "deviceLocation") {
                this.locationShow = true;
            }

            return index, prop;
        },

        refreshList() {},
        WBSDialog() { // WBS树关闭
            this.locationShow = false;
        },

        // WBS
        // 详情
        getDetail(obj) {
            this.loading = true;
            var str;
            var data;
            if (this.status == 0) {
                str = getEnvMonitorByFid; //监测记录
            } else if (this.status == 1) {
                str = getGantryCraneDetailsDataById; //龙门吊
            } else if (this.status == 2) {
                str = getBridgemachineByFid; //架桥机
            } else if (this.status == 3) {
                str = getTowercraneByFid; //塔吊
            } else if (this.status == 4) {
                str = getCradledataByFid; //挂篮
            } else if (this.status == 5) {
                str = getsmartElectricityDetailsDataById; //智慧用电
            }
            str(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    if (this.status == 0) {
                        data = res.data.yjQmpMsEnvMonitoring;
                    } else if (this.status == 1) {
                        data = res.data; //龙吊门
                    } else if (this.status == 2) {
                        data = res.data.yjQmpMsBridgemachinerecord; //架桥机
                    } else if (this.status == 3) {
                        data = res.data.yjQmpTowercranerecord; //塔吊
                    } else if (this.status == 4) {
                        data = res.data.yjQmpMsCradledata; //挂篮
                    } else if (this.status == 5) {
                        data = res.data; //智慧用电
                    }
                    if (this.status == 4) {
                        this.formData = data;
                        this.formData.rebar1IsOverweight = data.rebar1IsOverweight == 0 ? '正常' : '预警';
                        this.formData.rebar2IsOverweight = data.rebar2IsOverweight == 0 ? '正常' : '预警';
                        this.formData.rebar3IsOverweight = data.rebar3IsOverweight == 0 ? '正常' : '预警';
                        this.formData.rebar4IsOverweight = data.rebar4IsOverweight == 0 ? '正常' : '预警';
                    } else if (this.status == 5) {
                        this.formData = data;
                        this.formData.isDeleted = data.isDeleted == 0 ? '否' : '是';
                    } else {
                        this.formData = data;
                    }

                    // 
                    if (this.statusNum == 7) {
                        this.btnShow = false
                        this.formObj.map((item) => {
                            item.disabled = true;
                        });
                    } else {
                        this.btnShow = true;
                    }
                } else {
                    this.loading = false;
                    this.$message.error(res.msg);
                }
            });
        },



    },
};